package com.ruoyi.report_sj.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report_sj.domain.vo.ReportSjPhbsjsyjcbgBsInfoVo;
import com.ruoyi.report_sj.domain.bo.ReportSjPhbsjsyjcbgBsInfoBo;
import com.ruoyi.report_sj.service.IReportSjPhbsjsyjcbgBsInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 砂浆配合比设计试验检测报告
 *
 * @author zyb
 * @date 2024-05-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/reportsj/sjPhbsjsyjcbgBsInfo")
public class ReportSjPhbsjsyjcbgBsInfoController extends BaseController {

    private final IReportSjPhbsjsyjcbgBsInfoService iReportSjPhbsjsyjcbgBsInfoService;

    /**
     * 查询砂浆配合比设计试验检测报告列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<ReportSjPhbsjsyjcbgBsInfoVo> list(ReportSjPhbsjsyjcbgBsInfoBo bo, PageQuery pageQuery) {
        return iReportSjPhbsjsyjcbgBsInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出砂浆配合比设计试验检测报告列表
     */
    @SaCheckLogin
    @Log(title = "砂浆配合比设计试验检测报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ReportSjPhbsjsyjcbgBsInfoBo bo, HttpServletResponse response) {
        List<ReportSjPhbsjsyjcbgBsInfoVo> list = iReportSjPhbsjsyjcbgBsInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "砂浆配合比设计试验检测报告", ReportSjPhbsjsyjcbgBsInfoVo.class, response);
    }

    /**
     * 获取砂浆配合比设计试验检测报告详细信息
     *
     * @param excelId 主键
     */
    @SaCheckLogin
    @GetMapping("/{excelId}")
    public R<ReportSjPhbsjsyjcbgBsInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long excelId) {
        return R.ok(iReportSjPhbsjsyjcbgBsInfoService.queryById(excelId));
    }

    /**
     * 新增砂浆配合比设计试验检测报告
     */
    @SaCheckLogin
    @Log(title = "砂浆配合比设计试验检测报告", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ReportSjPhbsjsyjcbgBsInfoBo bo) {
        return toAjax(iReportSjPhbsjsyjcbgBsInfoService.insertByBo(bo));
    }

    /**
     * 修改砂浆配合比设计试验检测报告
     */
    @SaCheckLogin
    @Log(title = "砂浆配合比设计试验检测报告", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ReportSjPhbsjsyjcbgBsInfoBo bo) {
        return toAjax(iReportSjPhbsjsyjcbgBsInfoService.updateByBo(bo));
    }

    /**
     * 删除砂浆配合比设计试验检测报告
     *
     * @param excelIds 主键串
     */
    @SaCheckLogin
    @Log(title = "砂浆配合比设计试验检测报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{excelIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] excelIds) {
        return toAjax(iReportSjPhbsjsyjcbgBsInfoService.deleteWithValidByIds(Arrays.asList(excelIds), true));
    }

    @SaCheckLogin
    @Log(title = "砂浆配合比设计试验检测报告检测结论")
    @PutMapping("/jjcjl")
    public R<ReportSjPhbsjsyjcbgBsInfoVo> jcjl(@RequestBody ReportSjPhbsjsyjcbgBsInfoVo vo){
        return R.ok(iReportSjPhbsjsyjcbgBsInfoService.jcjl(vo));
    }

}
